﻿Imports System

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class FreeFormDesignerVerbProvider
        Implements IDesignerVerbProvider
        ' Methods
        Private Sub OnZOrderChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim verb As ActivityDesignerVerb = [TryCast](sender,ActivityDesignerVerb)
            If ((Not verb Is Nothing) AndAlso verb.Properties.Contains(DesignerUserDataKeys.ZOrderKey)) Then
                Dim parentDesigner As FreeformActivityDesigner = [TryCast](verb.ActivityDesigner.ParentDesigner,FreeformActivityDesigner)
                If (Not parentDesigner Is Nothing) Then
                    If (DirectCast(verb.Properties.Item(DesignerUserDataKeys.ZOrderKey), ZOrder) = ZOrder.Foreground) Then
                        parentDesigner.BringToFront(verb.ActivityDesigner)
                    ElseIf (DirectCast(verb.Properties.Item(DesignerUserDataKeys.ZOrderKey), ZOrder) = ZOrder.Background) Then
                        parentDesigner.SendToBack(verb.ActivityDesigner)
                    End If
                End If
            End If
        End Sub

        Private Sub OnZOrderStatusUpdate(ByVal sender As Object, ByVal e As EventArgs)
            Dim verb As ActivityDesignerVerb = [TryCast](sender,ActivityDesignerVerb)
            If ((Not verb Is Nothing) AndAlso verb.Properties.Contains(DesignerUserDataKeys.ZOrderKey)) Then
                Dim parentDesigner As FreeformActivityDesigner = [TryCast](verb.ActivityDesigner.ParentDesigner,FreeformActivityDesigner)
                If (Not parentDesigner Is Nothing) Then
                    verb.Enabled = parentDesigner.CanUpdateZOrder(verb.ActivityDesigner, DirectCast(verb.Properties.Item(DesignerUserDataKeys.ZOrderKey), ZOrder))
                End If
            End If
        End Sub

        Private Function System.Workflow.ComponentModel.Design.IDesignerVerbProvider.GetVerbs(ByVal activityDesigner As ActivityDesigner) As ActivityDesignerVerbCollection Implements IDesignerVerbProvider.GetVerbs
            Dim verbs As New ActivityDesignerVerbCollection
            If TypeOf activityDesigner.ParentDesigner Is FreeformActivityDesigner Then
                Dim verb As New ActivityDesignerVerb(activityDesigner, DesignerVerbGroup.Actions, DR.GetString("BringToFront", New Object(0  - 1) {}), New EventHandler(AddressOf Me.OnZOrderChanged), New EventHandler(AddressOf Me.OnZOrderStatusUpdate))
                verb.Properties.Item(DesignerUserDataKeys.ZOrderKey) = ZOrder.Foreground
                verbs.Add(verb)
                verb = New ActivityDesignerVerb(activityDesigner, DesignerVerbGroup.Actions, DR.GetString("SendToBack", New Object(0  - 1) {}), New EventHandler(AddressOf Me.OnZOrderChanged), New EventHandler(AddressOf Me.OnZOrderStatusUpdate))
                verb.Properties.Item(DesignerUserDataKeys.ZOrderKey) = ZOrder.Background
                verbs.Add(verb)
            End If
            Return verbs
        End Function

    End Class
End Namespace

